package com.wbao.dianniu.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.QaResponse;

/**
 * 我的回答list-adapter
 * 
 * @author yejianjun
 *
 */
public class AnswerListAdapter extends BaseAdapter {

	private Context context;
	private List<QaResponse> mList;
	private LayoutInflater mInflater;
	
	public AnswerListAdapter(Context ctx) {
		context = ctx;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mList = new ArrayList<QaResponse>();
	}
	
	public void setData(List<QaResponse> list){
		mList = list;
	}
	
	@Override
	public int getCount() {
		if (null == mList)
			return 0;
		else
			return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int index, View contentView, ViewGroup parent) {
		GridHolder holder;
		if (contentView == null) {
			contentView = mInflater.inflate(R.layout.answer_list_item, null);   
			holder = new GridHolder();
			holder.titleTV = (TextView)contentView.findViewById(R.id.answer_question_item);
			holder.timeTV =  (TextView)contentView.findViewById(R.id.answer_time_item);
			holder.responseTV = (TextView) contentView.findViewById(R.id.answer_response_item);
			contentView.setTag(holder); 
		}else{
			 holder = (GridHolder) contentView.getTag();   
		}
		QaResponse  data = mList.get(index);
		if (data != null) {
			holder.titleTV.setText(data.content);
			holder.timeTV.setText(data.createDate);
			holder.responseTV.setText(data.answerContent);
		}
		
		return contentView;
		
	}
	
	public class GridHolder {
		public TextView titleTV;
		public TextView timeTV;
		public TextView responseTV;
	}

}
